package com.university.report.user.handler;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.university.report.common.utils.MD5Util;
import com.university.report.model.entity.UserAccount;
import com.university.report.user.mapper.UserAccountMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @ClassName health_report
 * @Author Jinondo
 * @Date 2021/7/1 8:19
 */
@Slf4j
public class UserImportListener extends AnalysisEventListener<UserAccount> {

    UserAccountMapper userAccountMapper;

    public UserImportListener(UserAccountMapper userAccountMapper) {
        this.userAccountMapper = userAccountMapper;
    }

    @Override
    public void invoke(UserAccount userAccount, AnalysisContext analysisContext) {
        System.out.println(userAccount);
        userAccount.setPassword(MD5Util.encode(userAccount.getPassword()));
        userAccountMapper.insert(userAccount);
        userAccountMapper.insertOne(userAccount.getUserId(),Integer.parseInt(userAccount.getRoleName()));
        System.out.println(userAccount);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
